import time

from selenium import webdriver
from Case.python_ui.Common.basepage import Basepage
from Case.python_ui.PageLocate.admin_pu_user_locator import AdminPUUserLocator
from Case.python_ui.Common.commontool import CommonTool
from selenium.common.exceptions import StaleElementReferenceException
from Case.python_ui.Common.business_common_tool import BusinessCommonTools
from Case.python_ui.Test_data.login_data import Logindata
from Case.python_ui.PageLocate.login_locator import Loginlocator
from Case.python_ui.PageLocate.admin_basic_information_locator import adminBasicInformationLocator

class adminBasicInformationPages(Basepage):

   # 进入basic information页面
    def enter_basic_information_page(self):
       time.sleep(2)
       doc = "进入Basic Information菜单"
       # js_object = 'document.getElementsByClassName("cre-sider-menu cre-sider-menu-open")[0].scrollTop=10000'
       # self.excute_js(js_object);
       self.scroll_bar_operation(adminBasicInformationLocator.account_settings_menu)
       self.move_mouse_to_click_element(adminBasicInformationLocator.account_settings_menu, doc)
       self.wait_elevisble(adminBasicInformationLocator.basic_information_menu, doc)
       self.click_element(adminBasicInformationLocator.basic_information_menu, doc)

   # 按钮点击
   #  def get_operation_name_click(self, operation):
   #     doc = '通过操作的名称去点击'
   #     eles = self.get_elements(UserBasicInformationLocator, doc)
   #     for ele in eles:
   #          if ele.text == operation:
   #              time.sleep(2)
   #              ele.click()

   # 查看页面属性
    def view_basic_information_page(self):
        doc = '查看basic information页面字段属性'
        self.enter_basic_information_page()
        self.wait_elevisble(adminBasicInformationLocator.phone_number,doc)
        time.sleep(2)
        phone_number = self.get_element(adminBasicInformationLocator.phone_number,doc).text
        first_name = self.get_element(adminBasicInformationLocator.first_name, doc).text
        last_name = self.get_element(adminBasicInformationLocator.last_name, doc).text
        post_code = self.get_element(adminBasicInformationLocator.post_code, doc).text
        country_Region = self.get_element(adminBasicInformationLocator.country_region, doc).text
        state_province = self.get_element(adminBasicInformationLocator.state_province, doc).text
        city = self.get_element(adminBasicInformationLocator.city, doc).text
        address = self.get_element(adminBasicInformationLocator.address, doc).text
        return phone_number,first_name,last_name,post_code,country_Region,state_province,city,address



   # 编辑phone
    def edit_phone_number(self):
        self.enter_basic_information_page()
        time.sleep(2)
        doc = "编辑phone number"
        area_code = "256"
        phone_number = "1233456780"
        self.wait_elevisble(adminBasicInformationLocator.edit_phone_botton, doc)
        self.click_element(adminBasicInformationLocator.edit_phone_botton, doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.identity_verification_code_input0, doc)
        self.send_keys(adminBasicInformationLocator.identity_verification_code_input0, 8888, doc)
        self.click_element(adminBasicInformationLocator.continue_botton0, doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.area_code_input, doc)
        self.send_keys(adminBasicInformationLocator.area_code_input, area_code, doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.area_code_result, doc)
        self.click_element(adminBasicInformationLocator.area_code_result, doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.phone_input, doc)
        self.keyboard_event(adminBasicInformationLocator.phone_input, doc)
        self.send_keys(adminBasicInformationLocator.phone_input, phone_number, doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.identity_verification_code_input1, doc)
        self.send_keys(adminBasicInformationLocator.identity_verification_code_input1, 8888, doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.submit_botton0, doc)
        self.click_element(adminBasicInformationLocator.submit_botton0, doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.close_botton, doc)
        self.click_element(adminBasicInformationLocator.close_botton, doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.phone_number_value, doc)
        result = self.get_element(adminBasicInformationLocator.phone_number_value, doc).text
        return result

   # 编辑contact information
    def edit_contact_information(self):
        self.enter_basic_information_page()
        time.sleep(2)
        doc = "编辑conrtact information"
        self.wait_elevisble(adminBasicInformationLocator.edit_contact_information_botton, doc)
        self.click_element(adminBasicInformationLocator.edit_contact_information_botton, doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.first_name_input, doc)
        self.keyboard_event(adminBasicInformationLocator.first_name_input, doc)
        self.send_keys(adminBasicInformationLocator.first_name_input, "admin", doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.last_name_input, doc)
        self.keyboard_event(adminBasicInformationLocator.last_name_input, doc)
        self.send_keys(adminBasicInformationLocator.last_name_input, "admin", doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.post_code_input, doc)
        self.keyboard_event(adminBasicInformationLocator.post_code_input, doc)
        self.send_keys(adminBasicInformationLocator.post_code_input, 350001, doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.country_input, doc)
        self.send_keys(adminBasicInformationLocator.country_input, "China", doc)
        self.wait_elevisble(adminBasicInformationLocator.country_reslut, doc)
        self.click_element(adminBasicInformationLocator.country_reslut, doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.state_input, doc)
        self.keyboard_event(adminBasicInformationLocator.state_input, doc)
        self.send_keys(adminBasicInformationLocator.state_input, "fujian", doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.city_input, doc)
        self.keyboard_event(adminBasicInformationLocator.city_input, doc)
        self.send_keys(adminBasicInformationLocator.city_input, "fuzhou", doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.address_input, doc)
        self.keyboard_event(adminBasicInformationLocator.address_input, doc)
        self.send_keys(adminBasicInformationLocator.address_input, "gulouqu", doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.submit_botton1, doc)
        self.click_element(adminBasicInformationLocator.submit_botton1, doc)
        time.sleep(2)
        self.wait_elevisble(adminBasicInformationLocator.first_name_value, doc)
        first_name_value = self.get_element(adminBasicInformationLocator.first_name_value, doc).text
        last_name_value = self.get_element(adminBasicInformationLocator.last_name_value, doc).text
        post_code_value = self.get_element(adminBasicInformationLocator.post_code_value, doc).text
        country_Region_value = self.get_element(adminBasicInformationLocator.country_region_value, doc).text
        state_province_value = self.get_element(adminBasicInformationLocator.state_province_value, doc).text
        city_value = self.get_element(adminBasicInformationLocator.city_value, doc).text
        address_value = self.get_element(adminBasicInformationLocator.address_value, doc).text
        return first_name_value, last_name_value, post_code_value, country_Region_value, state_province_value, city_value, address_value











